<?php
/*
 * 用户中心
 */
namespace Mobile\Controller;

use Mobile\Model\moneylogModel;

class MoneylistsController extends BaseController {
    
    public $moneylogModel;
    
    public function __construct() {
        parent::__construct();
        $this->moneylogModel = new moneylogModel();
    }
    
  /*
     * 我的佣金流水
     */
    public function money(){
        $seo_data = array(
            "title" => "我的".C('YONGJIN_NAME'),
            "description" => "",
            "keywords" => "",
        );
        $this->setSeo($seo_data);

        
        $page_size = C("MOBILE_PAGESIZE");//分页条数
        $page = get('p',1);
        $where = array(
            'uid' => $this->uid,
            "mtype" =>array('in',array(1,12)),
            'un_Lock' => 1
        );
        $datalist = $this->moneylogModel->getMoneylogList($where, $page,$page_size);
        
        $a_count = $this->moneylogModel->where($where)->count();//总的记录数量
        $totalpage = ceil($a_count/$page_size);//向上取整,总的页码数
        $this->assign('totalpage',$totalpage);
        
        if(IS_AJAX){
            exit_json($datalist);
        }
        
        
    
        $this->assign('datalist',$datalist);
        
        $share_data = array(
            "title" => "我的".C('YONGJIN_NAME'),
        );
        $this->setShare($share_data);
        
        $this->display();
    }

    /*
     * 区域奖励
     */
    public function area(){
        $seo_data = array(
            "title" => "我的区域奖励",
            "description" => "",
            "keywords" => "",
        );
        $this->setSeo($seo_data);

        
        $page_size = C("MOBILE_PAGESIZE");//分页条数
        $page = get('p',1);
        $where = array(
            'uid' => $this->uid,
            "mtype" =>array('in',array(1,12)),
            'content' => array('like','区域')
        );
        $datalist = $this->moneylogModel->getMoneylogList($where, $page,$page_size);
        
        $a_count = $this->moneylogModel->where($where)->count();//总的记录数量
        $totalpage = ceil($a_count/$page_size);//向上取整,总的页码数
        $this->assign('totalpage',$totalpage);
        
        if(IS_AJAX){
            exit_json($datalist);
        }
        
    
        $this->assign('datalist',$datalist);
        
        $share_data = array(
            "title" => "我的区域奖励",
        );
        $this->setShare($share_data);
        
        $this->display();
    }
    
    public function prizemoney(){
        $seo_data = array(
            "title" => "我的".C('YONGJIN_NAME'),
            "description" => "",
            "keywords" => "",
        );
        $this->setSeo($seo_data);

        
        $page_size = C("MOBILE_PAGESIZE");//分页条数
        $page = get('p',1);
        $where = array(
            'uid' => $this->uid,
            "mtype" =>array('in',array(12)),
            'un_Lock' => 1
        );
        $datalist = $this->moneylogModel->getMoneylogList($where, $page,$page_size);
        
        $a_count = $this->moneylogModel->where($where)->count();//总的记录数量
        $totalpage = ceil($a_count/$page_size);//向上取整,总的页码数
        $this->assign('totalpage',$totalpage);
        
        if(IS_AJAX){
            exit_json($datalist);
        }
        
        
    
        $this->assign('datalist',$datalist);
        
        $share_data = array(
            "title" => "我的".C('YONGJIN_NAME'),
        );
        $this->setShare($share_data);
        
        $this->display();
    }
    
    /*
     * 我的锁定佣金流水
     */
    public function lockedmoney(){
        $seo_data = array(
            "title" => "我的".C('LOCAKED_MONEY'),
            "description" => "",
            "keywords" => "",
        );
        $this->setSeo($seo_data);
    
    
        $page_size = C("MOBILE_PAGESIZE");//分页条数
        $page = get('p',1);
        $where = array(
            'uid' => $this->uid,
            "mtype" =>1,
            'un_lock' => 0,
        );
        $datalist = $this->moneylogModel->getMoneylogList($where, $page,$page_size);
    
        $a_count = $this->moneylogModel->where($where)->count();//总的记录数量
        $totalpage = ceil($a_count/$page_size);//向上取整,总的页码数
        $this->assign('totalpage',$totalpage);
        
        
    
        if(IS_AJAX){
            exit_json($datalist);
        }
    
    
    
        $this->assign('datalist',$datalist);
    
        $share_data = array(
            "title" => "我的".C('LOCAKED_MONEY'),
        );
        $this->setShare($share_data);
    
        $this->display();
    }
    

    

    /*
     * 我的现金流水
     */
    public function cash(){
        $seo_data = array(
            "title" => "我的".C('CASH_NAME'),
            "description" => "",
            "keywords" => "",
        );
        $this->setSeo($seo_data);

        $page_size = C("MOBILE_PAGESIZE");//分页条数
        $page = get('p',1);
        $where = array(
            'uid' => $this->uid,
            "mtype" =>3
        );
        $datalist = $this->moneylogModel->getMoneylogList($where, $page,$page_size);
        
        $a_count = $this->moneylogModel->where($where)->count();//总的记录数量
        $totalpage = ceil($a_count/$page_size);//向上取整,总的页码数
        $this->assign('totalpage',$totalpage);
        
        if(IS_AJAX){
            exit_json($datalist);
           
        }
    
        $this->assign('datalist',$datalist);
    
        $share_data = array(
            "title" => "我的".C('CASH_NAME'),
        );
        $this->setShare($share_data);
    
        $this->display();
    }
    
    public function score(){
        $seo_data = array(
            "title" => "我的".C('SCORE_NAME'),
            "description" => "",
            "keywords" => "",
        );
        $this->setSeo($seo_data);

        $page_size = C("MOBILE_PAGESIZE");//分页条数
        $page = get('p',1);
        $where = array(
            'uid' => $this->uid,
            "mtype" =>2
        );
        $datalist = $this->moneylogModel->getMoneylogList($where, $page,$page_size);
        
        $a_count = $this->moneylogModel->where($where)->count();//总的记录数量
        $totalpage = ceil($a_count/$page_size);//向上取整,总的页码数
        $this->assign('totalpage',$totalpage);
        
        if(IS_AJAX){
            exit_json($datalist);
           
        }
    
        $this->assign('datalist',$datalist);
    
        $share_data = array(
            "title" => "我的".C('SCORE_NAME'),
        );
        $this->setShare($share_data);
    
        $this->display();
    }
    
    public function stock(){
        $seo_data = array(
            "title" => "我的库存",
            "description" => "",
            "keywords" => "",
        );
        $this->setSeo($seo_data);
        $page_size = C("MOBILE_PAGESIZE");//分页条数
        $page = get('p',1);
        $where = array(
            'uid' => $this->uid,
            "mtype" =>4
        );
        $datalist = $this->moneylogModel->getMoneylogList($where, $page,$page_size);
        $a_count = $this->moneylogModel->where($where)->count();//总的记录数量
        $totalpage = ceil($a_count/$page_size);//向上取整,总的页码数
        $this->assign('totalpage',$totalpage);
        if(IS_AJAX){
            exit_json($datalist);
        }
        $this->assign('datalist',$datalist);
        $share_data = array(
            "title" => "我的库存",
        );
        $this->setShare($share_data);
        $this->display();
    }

    public function moneydetail () {
        if(IS_AJAX) {
            $tab = get('tab');//全部 推荐奖 区域奖 年终奖
            $bar = get('bar');//全部 本月 今日
            $page = get('page',1);
            $where = array(
                'uid' => $this->memberinfo['uid']
            );
            if($tab==0) {
                $where['mtype'] = array('in',array(1,5));
            }
            if($tab==1) {
                $where['mtype'] = 1;
                $where['content'] = array('notlike','%区域%');
            }
            if($tab==2) {
                $where['mtype'] = 1;
                $where['content'] = array('like','%区域%');
            }
            if($tab==3) {
                $where['mtype'] = 5;
            }
            if($bar==0) {

            }
            if($bar==1) {
                $where['create_time'] = array('between',array(date('Y-m-01 00:00:00'),date('Y-m-d H:i:s')));
            }
            if($bar==2) {
                $where['create_time'] = array('between',array(date('Y-m-d 00:00:00'),date('Y-m-d 23:59:59')));
            }
            $list = $this->moneylogModel->where($where)->order('log_id desc')->page($page,20)->select();

            $orderModel = M('order');
            foreach($list as $k=>$v) {
                if($v['order_id']) {
                    $list[$k]['nickname'] = $orderModel->where(array('order_id'=>$v['order_id']))->getField('nickname');
                }
            }

            if(!$list) {
                return_json(1,'');
            }
            return_json(0,'',$list);
            exit;
        }
        $seo_data = array(
            "title" => "我的".C('YONGJIN_NAME'),
            "description" => "",
            "keywords" => "",
        );
        //本月奖励
        $data = array(
            'month' => getAllMoneyByDate($this->uid,date('Y-m-01 00:00:00'),date('Y-m-d H:i:s')),
            'day' => getAllMoneyByDate($this->uid,date('Y-m-d 00:00:00'),date('Y-m-d 23:59:59')),
            //'all' => round($this->memberinfo['money']+$this->memberinfo['lock_money'],2)
            'all' => getAllMoneyByDate($this->uid,date('2018-01-01 00:00:00'),date('Y-m-d 23:59:59'))
        );
        $this->assign('data',$data);
        $this->setSeo($seo_data);
        $this->display();
    }
    
}